//
//  MagazineHeaderTableViewCell.m
//  HelpThePoor
//
//  Created by van7ish on 2016/12/4.
//  Copyright © 2016年 van7ish. All rights reserved.
//

#import "MagazineHeaderTableViewCell.h"

@implementation MagazineHeaderTableViewCell

- (UIProgressView *)progressView{
    if (!_progressView) {
        _progressView = [[UIProgressView alloc] initWithFrame:CGRectMake(WidthScale(15), CGRectGetMaxY(self.readButton.frame) + HeightScale(5), SCREEN_W - WidthScale(30), HeightScale(5))];
        _progressView.layer.cornerRadius = 2;
        _progressView.progressTintColor = COLOR_GREEN;
        _progressView.transform = CGAffineTransformMakeScale(1.0f,3.0f);
        _progressView.progress = 0.5;
        _progressView.hidden = YES;
    }
    return _progressView;
}

- (UIButton *)downloadButton{
    if (!_downloadButton) {
        _downloadButton = [[UIButton alloc] initWithFrame:CGRectMake(SCREEN_W - WidthScale((15 + 70)), self.readButton.frame.origin.y, WidthScale(70), HeightScale(30))];
        [_downloadButton setImage:ImageNamed(@"下载") forState:UIControlStateNormal];
        __weak typeof(self)weakSelf = self;
        [_downloadButton initWithBlock:^(id obj) {
            DLog(@"下载");
            weakSelf.progressView.hidden = NO;
        } for:UIControlEventTouchUpInside];
    }
    return _downloadButton;
}

- (UIButton *)readButton{
    if (!_readButton) {
        _readButton = [[UIButton alloc] initWithFrame:CGRectMake(self.underLine.frame.origin.x, CGRectGetMaxY(self.underLine.frame) + HeightScale(8), WidthScale(70), HeightScale(30))];
        [_readButton setImage:ImageNamed(@"在线阅读") forState:UIControlStateNormal];
        
        [_readButton initWithBlock:^(id obj) {
            DLog(@"在线阅读")
        } for:UIControlEventTouchUpInside];
    }
    return _readButton;
}

- (UIView *)backView{
    if (!_backView) {
        _backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, HeightScale(350))];
        _backView.backgroundColor = COLOR_BOOKDETAILBGCOLOR;
    }
    return _backView;
}

- (UIImageView *)coverImageView{
    if (!_coverImageView) {
        _coverImageView = [[UIImageView alloc] initWithFrame:CGRectMake((SCREEN_W - WidthScale(170)) / 2, HeightScale(80), WidthScale(170), HeightScale(245))];
        _coverImageView.image = ImageNamed(@"8");
    }
    return _coverImageView;
}

- (UILabel *)titleLabel{
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(WidthScale(15), CGRectGetMaxY(self.backView.frame), self.frame.size.width, HeightScale(44))];
        _titleLabel.text = @"【今日教育杂志】";
        _titleLabel.textColor = COLOR_FONTBLACK;
        _titleLabel.font = FONTSIZE(18);
    }
    return _titleLabel;
}

- (UIView *)underLine{
    if (!_underLine) {
        _underLine = [[UILabel alloc] initWithFrame:CGRectMake(self.titleLabel.frame.origin.x, CGRectGetMaxY(self.titleLabel.frame) + HeightScale(2), SCREEN_W - self.titleLabel.frame.origin.x * 2, HeightScale(1))];
        _underLine.backgroundColor = COLOR_FONTBLACK;
    }
    return _underLine;
}

- (UILabel *)authorLabel{
    if (!_authorLabel) {
        _authorLabel = [[UILabel alloc] initWithFrame:CGRectMake(_titleLabel.frame.origin.x, CGRectGetMaxY(self.underLine.frame) + HeightScale(2), WidthScale(70), HeightScale(25))];
        _authorLabel.text = @"发行周期";
        _authorLabel.textColor = COLOR_FONTGRAY;
        _authorLabel.font = FONTSIZE(16);
    }
    return _authorLabel;
}

-(UILabel *)authorNameLabel{
    if (!_authorNameLabel) {
        _authorNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.authorLabel.frame) + WidthScale(15), self.authorLabel.frame.origin.y, WidthScale(300), self.authorLabel.frame.size.height)];
        _authorNameLabel.text = @"月刊";
        _authorNameLabel.textColor = COLOR_FONTGRAY;
        _authorNameLabel.font = FONTSIZE(16);
    }
    return _authorNameLabel;
}

- (UILabel *)publishTimeLabel{
    if (!_publishTimeLabel) {
        _publishTimeLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.authorLabel.frame.origin.x, CGRectGetMaxY(self.authorLabel.frame), self.authorLabel.frame.size.width, self.authorLabel.frame.size.height)];
        _publishTimeLabel.text = @"国内刊号";
        _publishTimeLabel.textColor = COLOR_FONTGRAY;
        _publishTimeLabel.font = FONTSIZE(16);
    }
    return _publishTimeLabel;
}

- (UILabel *)timeLabel{
    if (!_timeLabel) {
        _timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.authorNameLabel.frame.origin.x, CGRectGetMaxY(self.authorNameLabel.frame), self.authorNameLabel.frame.size.width, self.authorNameLabel.frame.size.height)];
        _timeLabel.text = @"05-1131/G4";
        _timeLabel.textColor = COLOR_FONTGRAY;
        _timeLabel.font = FONTSIZE(16);
    }
    return _timeLabel;
}

- (UILabel *)publishHouseLabel{
    if (!_publishHouseLabel) {
        _publishHouseLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.authorLabel.frame.origin.x, CGRectGetMaxY(self.publishTimeLabel.frame), self.authorLabel.frame.size.width, self.authorLabel.frame.size.height)];
        _publishHouseLabel.text = @"出  版  社";
        _publishHouseLabel.textColor = COLOR_FONTGRAY;
        _publishHouseLabel.font = FONTSIZE(16);
    }
    return _publishHouseLabel;
}

- (UILabel *)houseLabel{
    if (!_houseLabel) {
        _houseLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.authorNameLabel.frame.origin.x, CGRectGetMaxY(self.timeLabel.frame), self.authorNameLabel.frame.size.width, self.authorNameLabel.frame.size.height)];
        _houseLabel.text = @"重庆出版公司";
        _houseLabel.textColor = COLOR_FONTGRAY;
        _houseLabel.font = FONTSIZE(16);
    }
    return _houseLabel;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.contentView.backgroundColor = COLOR_LIGHTBGCOLOR;
    [self.contentView addSubview:self.backView];
    [self.backView addSubview:self.coverImageView];
    [self.contentView addSubview:self.titleLabel];
    [self.contentView addSubview:self.underLine];
    [self.contentView addSubview:self.readButton];
    [self.contentView addSubview:self.downloadButton];
    [self.contentView addSubview:self.progressView];
    [self.contentView addSubview:self.authorLabel];
    [self.contentView addSubview:self.authorNameLabel];
    [self.contentView addSubview:self.publishTimeLabel];
    [self.contentView addSubview:self.timeLabel];
    [self.contentView addSubview:self.publishHouseLabel];
    [self.contentView addSubview:self.houseLabel];
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
